package com.fresh.api;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fresh.common.annotation.IgnoreAuth;
import com.fresh.dao.PayRecordDao;
import com.fresh.dao.ScoreDao;
import com.fresh.dao.VerifyDao;
import com.fresh.entity.AntifraudUser;
import com.fresh.entity.BlackEntity;
import com.fresh.entity.ChsiResultEntity;
import com.fresh.entity.DataInterfaceManagement;
import com.fresh.entity.DictEntity;
import com.fresh.entity.GsResultEntity;
import com.fresh.entity.ITEM_DETAIL;
import com.fresh.entity.JDEntity;
import com.fresh.entity.NutSummaryData;
import com.fresh.entity.NutSummaryEntity;
import com.fresh.entity.NutSummaryShoppingRecordInfos;
import com.fresh.entity.OVERDUE_DETAILS;
import com.fresh.entity.RISK_ITEMS;
import com.fresh.entity.RuleData;
import com.fresh.entity.SHE_BAOResultEntity;
import com.fresh.entity.SMHMDDetail;
import com.fresh.entity.SMJDData;
import com.fresh.entity.SMJDEntity;
import com.fresh.entity.ShopPrice;
import com.fresh.entity.TdRiskReturn;
import com.fresh.entity.YysResultCallInfo;
import com.fresh.entity.YysResultEntity;
import com.fresh.entity.YysResultTaskData;
import com.fresh.entity.ZxExternalData;
import com.fresh.entity.ZxExternalSource;
import com.fresh.entity.ZxShopEntity;
import com.fresh.service.UserPermissionService;
import com.fresh.service.VerifyService;
import com.fresh.utils.Base64Utils;
import com.fresh.utils.Constant;
import com.fresh.utils.DateUtils;
import com.fresh.utils.Enums;
import com.fresh.utils.HttpUtils;
import com.fresh.utils.PropertiesUtils;
import com.google.gson.Gson;

/**
 * 反欺诈功能
 * 
 * @author mengxiangdong
 * @version 1.0
 * @date 2017年10月16日下午5:40:14 福乐康 Copyright© All Reserved 官方网站：www.flksh.com
 *       未经授权不得进行修改、复制、出售及商业使用
 */
@RequestMapping({ "/antifraud" })
@Controller
public class AntifraudController {
	private static final Logger log = LoggerFactory
			.getLogger(AntifraudController.class);

	@Autowired
	private VerifyService verifyService;

	@Autowired
	private VerifyDao verifyDao;

	@Autowired
	private ScoreDao scoreDao;
	
	@Autowired
	private PayRecordDao payRecordDao;
	
	@Autowired
	private UserPermissionService userPermissionService;
	
	int tdtype = 0;
	
	int smtype = 0;   //数美:0开启，1禁用
	
	@IgnoreAuth
	@RequestMapping({ "toIndex" })
	public String toIndex(HttpServletRequest request, AntifraudUser user)
			throws Exception {
		log.info("#toantiFraud() 进入首页！");
		return "/index";
	}

	@IgnoreAuth
	@RequestMapping({ "toantiFraud" })
	public String toantiFraud(HttpServletRequest request, AntifraudUser user,HttpServletResponse response)
			throws Exception {
		//权限拦截
		verifyService.permissionIntercept(Constant.ANTIFRAUD_PER, response, request);
		Gson gson=new Gson();
		log.info("#toantiFraud() 进入反欺诈查询页！");
		return "/buyer/antiFraud";
	}

	@IgnoreAuth
	@RequestMapping({ "toscorecard" })
	public String toscorecard(HttpServletRequest request, AntifraudUser user,HttpServletResponse response)
			throws Exception {
		//权限拦截
		verifyService.permissionIntercept(Constant.SCORECARD_PER, response, request);
		log.info("#toantiFraud() 进入评分卡查询页！");
		return "/buyer/scoreCard";
	}

	@IgnoreAuth
	@RequestMapping({ "toAddInfo" })
	public String toAddInfo(HttpServletRequest request, AntifraudUser user)
			throws Exception {
		request.setAttribute("id", user.getId());
		
		ZxExternalData zxExternalData=new ZxExternalData();
		zxExternalData.setId(user.getId());
		List<ZxExternalData> zxList=verifyDao.findOne(zxExternalData);
		
		if (zxList.size()>0) {
			request.getSession().setAttribute("USER_SCORE", zxList.get(0)); 
		}
		log.info("#toantiFraud() 进入评分卡下一步页面！");
		return "/buyer/addInfo";
	}

	@IgnoreAuth
	@RequestMapping({ "toScoreResult" })
	public String toScoreResult(HttpServletRequest request,RuleData ruleData,HttpServletResponse response)
			throws Exception {
		Gson gson=new Gson();
		String shopId=null;
		if (request.getSession().getAttribute("SHOP_ID")!=null) {
			 shopId = request.getSession().getAttribute("SHOP_ID").toString();  //商户Id
		}else{
			 PrintWriter out = response.getWriter();  
		        out.println("<html>");      
		        out.println("<script>"); 
		        out.println("window.open ('"+request.getContextPath()+"/index','_top')");      
		        out.println("</script>");
		        out.println("</html>");
			return null;
		}
		ruleData.setShopId(shopId);
		
		//报告编号
		String reportNum=getString16Date2(new Date());
		request.setAttribute("reportNum", reportNum);
		//报告生成时间
		String generateTime=getString16Date(new Date());
		request.setAttribute("generateTime", generateTime);
		
		List<ZxShopEntity> zxShopList=scoreDao.findZxShop();   //所有信用电话
		ZxExternalData zxExternalData=null;
		if (request.getSession().getAttribute("USER_SCORE")!=null) {
			 zxExternalData=(ZxExternalData) request.getSession().getAttribute("USER_SCORE");
			log.info("#getGs() 当前评分卡查询人:" + gson.toJson(zxExternalData));
			
		}else{
			 PrintWriter out = response.getWriter();
		        out.println("<html>");      
		        out.println("<script>");      
		        out.println("window.open ('"+request.getContextPath()+"/index','_top')");      
		        out.println("</script>");      
		        out.println("</html>");    
			return null;
		}
		ZxExternalSource zxExternalSource=new ZxExternalSource();
		zxExternalSource.setExternalId(zxExternalData.getId());
		zxExternalSource.setShopId(shopId);
		List<ZxExternalSource> sourceList=verifyDao.findSource(zxExternalSource);
		List<RuleData> ruleList=scoreDao.findScoreList(ruleData);
		int score=0;
		if (scoreDao.findScoreSum(ruleData)!=null) {
			score=scoreDao.findScoreSum(ruleData).getSum();
		}
		request.setAttribute("scoreSum", score);
		int chsiScore=0;
		int gjjScore=0;
		int shebaoScore=0;
		int yysScore=0;
		int nutScore=0;
		int chsi=0;
		int gjjting=0;
		int gjjduan=0;
		int sheting=0;
		int duanting=0;
		int total_msg_cost=0;   //联系人信息条数
		int yysMsg=0;
		int bill_fee=0;      //半年手机号平均消费金额 
		int bill=0;
		int netTime=0;    //手机号注册到现在的天数
		int net=0;
		int total_call_count=0;  //过去一个月累计通话次数
		int totalcallcount=0;
		int total_call_time=0;    //过去一个月累计通话时长
		int totalcalltime=0;
		int isRealInfo=0;      //是否登记
		double inCome=0;       //银行卡总收入
		double toPay=0;        //银行卡总支出
		int iscome=0;
		int ispay=0;
		int nutonly=0;
		int callCount=0;      //最近一个月主叫次数
		int calledCount=0;     //最近一个月被叫次数
		int iscall=0;
		int iscalled=0;
		int creditCount=0;     //信用电话通话次数
		int credit=0;
		int creditTime=0;     //信用电话通话时长
		int isCreditCount=0;
		int isCreditTime=0;  
		log.info("#toScoreResult() 外部数据："+gson.toJson(sourceList));
		
		for (int i = 0; i < sourceList.size(); i++) {
			ZxExternalSource zxSource=sourceList.get(i);
			
			//学信网
			if (chsi==0 && zxSource.getType().equals("2") && zxSource.getDataSource().contains(zxExternalData.getIdNumber())) {
				ChsiResultEntity chsiResultEntity=gson.fromJson(zxSource.getDataSource(), ChsiResultEntity.class);
				request.setAttribute("chsiList", chsiResultEntity);
				request.setAttribute("chsiType", "1");
				if (!chsiResultEntity.getData().getEducation_info().isEmpty()) {
					String imgName=Base64Utils.GenerateImage(chsiResultEntity.getData().getSchool_info().get(0).getHead_img());
					String getImg_url = PropertiesUtils.getProperty("getImg_url");
					request.setAttribute("imgUrl", getImg_url+imgName+".jpg");
					chsi=1;
				}
			}
			
			
			//公积金
			if (zxSource.getType().equals("3") && zxSource.getDataSource().contains(zxExternalData.getIdNumber())) {
				GsResultEntity gsResultEntity=gson.fromJson(zxSource.getDataSource(), GsResultEntity.class);
				request.setAttribute("gjjList", gsResultEntity.getData());
				request.setAttribute("gjjType", "1");
				if (zxSource.getDataSource().contains("停缴")) {
					request.setAttribute("tingType", "停缴");
				}else
				if (gsResultEntity.getData()==null) {
					request.setAttribute("tingType", "断缴");
				}else{
					request.setAttribute("tingType", "正常");
				}
				
				if (gjjting==0 && !zxSource.getDataSource().contains("停缴")) {
					gjjting=1;
				}
				
				if (gjjting==0 && gsResultEntity.getData()!=null) {
					gjjduan=1;
				}
			}
			
			//社保
			if (zxSource.getType().equals("4") && zxSource.getDataSource().contains(zxExternalData.getIdNumber())) {
				SHE_BAOResultEntity sHE_BAOResultEntity=gson.fromJson(zxSource.getDataSource(), SHE_BAOResultEntity.class);
				request.setAttribute("sheList", sHE_BAOResultEntity.getData());
				request.setAttribute("sheType", "1");
				
				if (zxSource.getDataSource().contains("停缴")) {
					request.setAttribute("she_baoType", "停缴");
				}else
				if (sHE_BAOResultEntity.getData()==null) {
					request.setAttribute("she_baoType", "断缴");
				}else{
					request.setAttribute("she_baoType", "正常");
				}
				
				if (sheting==0 && !zxSource.getDataSource().contains("停缴")) {
					sheting=1;
				}
				
				if (duanting==0 && sHE_BAOResultEntity.getData()!=null) {
					duanting=1;
				}
			}
			
			//运营商
			if (zxSource.getType().equals("5") && zxSource.getDataSource().contains(zxExternalData.getIdNumber())) {
				YysResultEntity yysResultEntity=gson.fromJson(zxSource.getDataSource(), YysResultEntity.class); 
				YysResultTaskData yysResultTaskData=yysResultEntity.getData().getTask_data();
				request.setAttribute("yysList", yysResultEntity);
				request.setAttribute("yysType", "1");
				
				//通话记录中所有联系人信息条数
				for (int j = 0; j < yysResultTaskData.getSms_info().size(); j++) {
					if (yysResultTaskData.getSms_info().get(j).getTotal_msg_count()!=null) {
						total_msg_cost= total_msg_cost+Integer.parseInt(yysResultTaskData.getSms_info().get(j).getTotal_msg_count());
					}
				}
				
				//过去 6 个月平均消费金额 
				int bill_feeSum=0;
				for (int j = 0; j < yysResultTaskData.getBill_info().size(); j++) {
					bill_feeSum =bill_feeSum+Integer.parseInt(yysResultTaskData.getBill_info().get(j).getBill_fee());
					bill_fee=bill_feeSum/yysResultTaskData.getBill_info().size();
				}
				
				//注册时间到现在的天数
				String net_time=yysResultTaskData.getAccount_info().getNet_time();
				String now_time=getStringDate(new Date());
				netTime=DateUtils.daysBetween(net_time, now_time);
				
				
				String lastMonth=lastMonth();
				for (int j = 0; j < yysResultTaskData.getCall_info().size(); j++) {
					YysResultCallInfo yysResultCallInfo=yysResultTaskData.getCall_info().get(j);
					if (yysResultCallInfo.getCall_cycle().equals(lastMonth)) {
						//过去 1 个月累计通话次数
						total_call_count=Integer.parseInt(yysResultCallInfo.getTotal_call_count());
						//过去 1 个月累计通话时长
						total_call_time=Integer.parseInt(yysResultCallInfo.getTotal_call_time())/60;
						
						for (int k = 0; k < yysResultCallInfo.getCall_record().size(); k++) {
							if (yysResultCallInfo.getCall_record().get(k).getCall_type_name().equals("主叫")) {
								//最近一个月呼出电话总次数
								callCount=callCount+1;
							}
							
							if (yysResultCallInfo.getCall_record().get(k).getCall_type_name().equals("被叫")) {
								//最近一个月呼入电话总次数
								calledCount=calledCount+1;
							}
							
						}
						
					}
				}
				
				//是否实名
				if (yysResultTaskData.getAccount_info().getReal_info().equals("已登记")) {
					isRealInfo=1;
				}
				
				
				if (yysResultTaskData.getCall_info().size()>=3 && credit==0) {
					for (int k = 0; k < 3; k++) {
						YysResultCallInfo yysResultCallInfo2=yysResultTaskData.getCall_info().get(k);
						
						for (int l = 0; l < zxShopList.size(); l++) {
							if (yysResultCallInfo2.getCall_cycle().contains(zxShopList.get(l).getFeaturePhone())) {
								//近 90 天内与信用卡中心通话次数
								creditCount=creditCount+1;
								
								//近 90 天内与信用卡中心通话时长
								creditTime=Integer.parseInt(creditTime+yysResultCallInfo2.getTotal_call_time())/60;
							}
						}
					}
					credit=1;
				}
				
				
				if (yysResultTaskData.getBill_info().size()>=1) {
					//1个月消费金额
					String oneMonthFee=yysResultTaskData.getBill_info().get(0).getBill_fee();
					request.setAttribute("oneMonthFee", Integer.parseInt(oneMonthFee)/100);
				}
				
				if (yysResultTaskData.getBill_info().size()>=2) {
					//第2个月消费金额
					String twoMonthFee=yysResultTaskData.getBill_info().get(1).getBill_fee();
					request.setAttribute("twoMonthFee", Integer.parseInt(twoMonthFee)/100);
				}
				
				if (yysResultTaskData.getBill_info().size()>=3) {
					//第3个月消费金额
					String threeMonthFee=yysResultTaskData.getBill_info().get(2).getBill_fee();
					request.setAttribute("threeMonthFee", Integer.parseInt(threeMonthFee)/100);
				}
				
				int zhuCallOne=0;
				int beiCallone=0;
				int oneMonthTime=0;
				int xinYongOneCount=0;
				int xinYongOneTime=0;
				List<String> resOneList = new ArrayList<String>();
				List<String> resTwoList = new ArrayList<String>();
				List<String> resThreeList = new ArrayList<String>();
				if (yysResultTaskData.getCall_info().size()>=1) {
					for (int j = 0; j < yysResultTaskData.getCall_info().get(0).getCall_record().size(); j++) {
						if (yysResultTaskData.getCall_info().get(0).getCall_record().get(j).getCall_type_name().contains("主叫")) {
							//第一个月主叫次数
							zhuCallOne=zhuCallOne+1;
						}
						if (yysResultTaskData.getCall_info().get(0).getCall_record().get(j).getCall_type_name().contains("被叫")) {
							//第一个月主叫次数
							beiCallone=beiCallone+1;
						}
						//第一个月通话时长
						oneMonthTime=Integer.parseInt(yysResultTaskData.getCall_info().get(0).getTotal_call_time())/60;
						
						
						for (int l = 0; l < zxShopList.size(); l++) {
							if (yysResultTaskData.getCall_info().get(0).getCall_cycle().contains(zxShopList.get(l).getFeaturePhone())) {
								//第一个月与信用卡中心通话次数
								xinYongOneCount=xinYongOneCount+1;
								//第一个月与信用卡中心通话时长
								xinYongOneTime=xinYongOneTime+Integer.parseInt(yysResultTaskData.getCall_info().get(0).getTotal_call_time());
							}
						}
						
						//第一个月通话最多的三个号码
						List<String> callOneList=new ArrayList<String>();
						for (int j2 = 0; j2 < yysResultTaskData.getCall_info().get(0).getCall_record().size(); j2++) {
							callOneList.add(yysResultTaskData.getCall_info().get(0).getCall_record().get(j2).getCall_other_number());
						}
						resOneList = getThree(callOneList);
						
					}
				}
				
				int zhuCallTwo=0;
				int beiCallTwo=0;
				int twoMonthTime=0;
				int xinYongTwoCount=0;
				int xinYongTwoTime=0;
				if (yysResultTaskData.getCall_info().size()>=2) {
					for (int j = 0; j < yysResultTaskData.getCall_info().get(0).getCall_record().size(); j++) {
						if (yysResultTaskData.getCall_info().get(1).getCall_record().get(j).getCall_type_name().contains("主叫")) {
							//第2个月主叫次数
							zhuCallTwo=zhuCallTwo+1;
						}
						if (yysResultTaskData.getCall_info().get(1).getCall_record().get(j).getCall_type_name().contains("被叫")) {
							//第2个月主叫次数
							beiCallTwo=beiCallTwo+1;
						}
						//第2个月通话时长
						twoMonthTime=Integer.parseInt(yysResultTaskData.getCall_info().get(1).getTotal_call_time())/60;
						
						
						for (int l = 0; l < zxShopList.size(); l++) {
							if (yysResultTaskData.getCall_info().get(1).getCall_cycle().contains(zxShopList.get(l).getFeaturePhone())) {
								//第2个月与信用卡中心通话次数
								xinYongTwoCount=xinYongTwoCount+1;
								//第2个月与信用卡中心通话时长
								xinYongTwoTime=xinYongTwoTime+Integer.parseInt(yysResultTaskData.getCall_info().get(1).getTotal_call_time());
							}
						}
						
						//第2个月通话最多的三个号码
						List<String> callOneList=new ArrayList<String>();
						for (int j2 = 0; j2 < yysResultTaskData.getCall_info().get(1).getCall_record().size(); j2++) {
							callOneList.add(yysResultTaskData.getCall_info().get(1).getCall_record().get(j2).getCall_other_number());
						}
						resTwoList = getThree(callOneList);
					}
				}
				
				
				int zhuCallThree=0;
				int beiCallThree=0;
				int threeMonthTime=0;
				int xinYongThreeCount=0;
				int xinYongThreeTime=0;
				if (yysResultTaskData.getCall_info().size()>=3) {
					for (int j = 0; j < yysResultTaskData.getCall_info().get(0).getCall_record().size(); j++) {
						if (yysResultTaskData.getCall_info().get(2).getCall_record().get(j).getCall_type_name().contains("主叫")) {
							//第3个月主叫次数
							zhuCallThree=zhuCallThree+1;
						}
						if (yysResultTaskData.getCall_info().get(2).getCall_record().get(j).getCall_type_name().contains("被叫")) {
							//第3个月主叫次数
							beiCallThree=beiCallThree+1;
						}
						//第3个月通话时长
						threeMonthTime=Integer.parseInt(yysResultTaskData.getCall_info().get(2).getTotal_call_time())/60;
						
						for (int l = 0; l < zxShopList.size(); l++) {
							if (yysResultTaskData.getCall_info().get(2).getCall_cycle().contains(zxShopList.get(l).getFeaturePhone())) {
								//第2个月与信用卡中心通话次数
								xinYongThreeCount=xinYongThreeCount+1;
								//第2个月与信用卡中心通话时长
								xinYongThreeTime=xinYongThreeTime+Integer.parseInt(yysResultTaskData.getCall_info().get(2).getTotal_call_time());
							}
						}
						
						
						//第3个月通话最多的三个号码
						List<String> callOneList=new ArrayList<String>();
						for (int j2 = 0; j2 < yysResultTaskData.getCall_info().get(2).getCall_record().size(); j2++) {
							callOneList.add(yysResultTaskData.getCall_info().get(2).getCall_record().get(j2).getCall_other_number());
						}
						resThreeList = getThree(callOneList);
					}
				}
				
				request.setAttribute("zhuCallOne", zhuCallOne);
				request.setAttribute("beiCallOne", beiCallTwo);
				request.setAttribute("zhuCallTwo", zhuCallTwo);
				request.setAttribute("beiCallTwo", beiCallTwo);
				request.setAttribute("zhuCallThree", zhuCallThree);
				request.setAttribute("beiCallThree", beiCallThree);
				request.setAttribute("oneMonthTime", oneMonthTime);
				request.setAttribute("twoMonthTime", twoMonthTime);
				request.setAttribute("threeMonthTime", threeMonthTime);
				
				request.setAttribute("xinYongOneCount", xinYongOneCount);
				request.setAttribute("xinYongOneTime", xinYongOneTime);
				
				request.setAttribute("xinYongTwoCount", xinYongTwoCount);
				request.setAttribute("xinYongTwoTime", xinYongTwoTime);
				
				request.setAttribute("xinYongThreeCount", xinYongThreeCount);
				request.setAttribute("xinYongThreeTime", xinYongThreeTime);
				request.setAttribute("resOneList", resOneList);
				request.setAttribute("resTwoList", resTwoList);
				request.setAttribute("resThreeList", resThreeList);
			}
			
			//银行卡
			if (nutonly==0 && zxSource.getType().equals("6") && (zxSource.getDataSource().contains(zxExternalData.getIdNumber()) || zxSource.getDataSource().contains(zxExternalData.getName()))) {
				request.setAttribute("nutType", "1");
				NutSummaryEntity nutSummaryEntity=gson.fromJson(zxSource.getDataSource(), NutSummaryEntity.class);
				request.setAttribute("nutList", nutSummaryEntity.getData());
				NutSummaryData nutSummaryData=nutSummaryEntity.getData();
				
				for (int j = 0; j < nutSummaryData.getBillMonthDtos().size(); j++) {
					List<NutSummaryShoppingRecordInfos> shopList=nutSummaryData.getBillMonthDtos().get(j).getShoppingRecordInfos();
					for (int j2 = 0; j2 < shopList.size(); j2++) {
						NutSummaryShoppingRecordInfos shop=shopList.get(j2);
						if (Double.parseDouble(shop.getAmountMoney())>0) {
							inCome=inCome+Double.parseDouble(shop.getAmountMoney());
						}
						if (Double.parseDouble(shop.getAmountMoney())<0) {
							toPay=Math.abs(toPay+Double.parseDouble(shop.getAmountMoney()));
						}
					}
				}
				nutonly=1;
				request.setAttribute("inCome", inCome);
				request.setAttribute("toPay", toPay);
			}
			
			
		
		}
		
		for (int j = 0; j < ruleList.size(); j++) {
			RuleData ruleD = ruleList.get(j);
		
			//学信网
			if (chsi==1 && ruleD.getRuleCode().equalsIgnoreCase("FLK-14")) {
				log.info("#toScoreResult() 学信网！");
				chsiScore=chsiScore+ruleD.getStore();
				chsi=2;
				continue;
			}
			
			if (ruleD.getType().contains("公积金")) {
	
				//公积金停缴
				if (gjjting==1 && ruleD.getRuleCode().equalsIgnoreCase("FLK-4")) {
					log.info("#toScoreResult() 公积金停缴！");
					gjjting=2;
					gjjScore=gjjScore+ruleD.getStore();
					continue;
				}
				//公积金断缴
				if (gjjduan==1 && ruleD.getRuleCode().equalsIgnoreCase("FLK-12")) {
					log.info("#toScoreResult() 公积金断缴！");
					gjjduan=2;
					gjjScore=gjjScore+ruleD.getStore();
					continue;
				}
			
			}
			
			if (ruleD.getType().contains("社保")) {
				
				//社保停缴
				if (sheting==1 && ruleD.getRuleCode().equalsIgnoreCase("FLK-2")) {
					log.info("#toScoreResult() 社保停缴！");
					sheting=2;
					shebaoScore=shebaoScore+ruleD.getStore();
					continue;
				}
				//社保断缴
				if (duanting==1 && ruleD.getRuleCode().equalsIgnoreCase("FLK-5")) {
					log.info("#toScoreResult() 社保断缴！");
					duanting=2;
					shebaoScore=shebaoScore+ruleD.getStore();
					continue;
				}
			}
			
			if (ruleD.getType().contains("运营商")) {
				
				//联系人信息条数
				if (ruleD.getRuleCode().equalsIgnoreCase("FLK-3")) {
					if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
					if ((total_msg_cost+1<=Integer.parseInt(ruleD.getMinValue()) || total_msg_cost>Integer.parseInt(ruleD.getMxValue())) && yysMsg==0) {
						yysMsg=1;
						yysScore=yysScore+ruleD.getStore();
						log.info("#toScoreResult() 联系人信息条数！");
						continue;
					}
					}
				}
				
				//6 个月平均消费金额
				if (ruleD.getRuleCode().equalsIgnoreCase("FLK-6")) {
					int billres=(bill_fee/100);
					if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
					if ((billres+1<=Integer.parseInt(ruleD.getMinValue()) || billres>Integer.parseInt(ruleD.getMxValue()))  && bill==0) {
						bill=1;
						yysScore=yysScore+ruleD.getStore();
						log.info("#toScoreResult() 6 个月平均消费金额！");
						continue;
					}
					}
				}
				
				//到现在的天数
				if (ruleD.getRuleCode().equalsIgnoreCase("FLK-8")) {
					if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
					if ((netTime+1<=Integer.parseInt(ruleD.getMinValue()) || netTime>Integer.parseInt(ruleD.getMxValue())) && net==0) {
						net=1;
						yysScore=yysScore+ruleD.getStore();
						log.info("#toScoreResult() 到现在的天数！");
						continue;
					}
					}
				}
				
				//1 个月累计通话次数
				if (ruleD.getRuleCode().equalsIgnoreCase("FLK-11")) {
					if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
					if ((total_call_count+1<=Integer.parseInt(ruleD.getMinValue()) || total_call_count>Integer.parseInt(ruleD.getMxValue()))  && totalcallcount==0) {
						totalcallcount=1;
						yysScore=yysScore+ruleD.getStore();
						log.info("#toScoreResult() 1 个月累计通话次数！");
						continue;
					}
					}
				}
				
				//1 个月累计通话时长
				if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
				if (ruleD.getRuleCode().equalsIgnoreCase("FLK-17")) {
					if ((total_call_time+1<=Integer.parseInt(ruleD.getMinValue()) || total_call_time>Integer.parseInt(ruleD.getMxValue())) &&  totalcalltime==0) {
						totalcalltime=1;
						yysScore=yysScore+ruleD.getStore();
						log.info("#toScoreResult() 1 个月累计通话时长！");
						continue;
					}
				}
				}
				
				//是否实名
				if (ruleD.getRuleCode().equalsIgnoreCase("FLK-13") && isRealInfo==1) {
					isRealInfo=2;
					yysScore=yysScore+ruleD.getStore();
					log.info("#toScoreResult() 是否实名！");
					continue;
				}
				
				//一个月呼出电话总次数
				if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
				if ((callCount+1<=Integer.parseInt(ruleD.getMinValue()) || callCount>Integer.parseInt(ruleD.getMxValue())) && ruleD.getRuleCode().equalsIgnoreCase("FLK-9") && iscall==0) {
					iscall=1;
					yysScore=yysScore+ruleD.getStore();
					log.info("#toScoreResult() 最近一个月呼出电话总次数！");
					continue;
				}
				}
				
				//最近一个月呼入电话总次数
				if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
				if ((calledCount+1<=Integer.parseInt(ruleD.getMinValue()) || calledCount>Integer.parseInt(ruleD.getMxValue())) && ruleD.getRuleCode().equalsIgnoreCase("FLK-10") && iscalled==0) {
					iscalled=1;
					yysScore=yysScore+ruleD.getStore();
					log.info("#toScoreResult() 最近一个月呼入电话总次数！");
					continue;
				}
				}
				
				 //90 天内与信用卡中心通话次数！
				if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
				if ((creditCount+1<=Integer.parseInt(ruleD.getMinValue()) || creditCount>=Integer.parseInt(ruleD.getMxValue())) && ruleD.getRuleCode().equalsIgnoreCase("FLK-7") && isCreditCount==0) {
					isCreditCount=1;
					yysScore=yysScore+ruleD.getStore();
					log.info("#toScoreResult() 90 天内与信用卡中心通话次数！");
					continue;
				}
				}
				
				//近 90 天内与信用卡中心通话时长！
				if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
				if ((creditTime+1<=Integer.parseInt(ruleD.getMinValue()) || creditTime>=Integer.parseInt(ruleD.getMxValue())) && ruleD.getRuleCode().equalsIgnoreCase("FLK-1") && isCreditTime==0) {
					isCreditTime=1;
					yysScore=yysScore+ruleD.getStore();
					log.info("#toScoreResult()近 90 天内与信用卡中心通话时长！");
					continue;
				}
				}
				
			}
			
			if (ruleD.getType().contains("银行卡")) {
				
				//银行卡收入
				if (ruleD.getRuleCode().equalsIgnoreCase("FLK-16")) {
					if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
					if ((inCome+1<=Integer.parseInt(ruleD.getMinValue()) || inCome>Integer.parseInt(ruleD.getMxValue())) &&  iscome==0) {
						iscome=1;
						nutScore=nutScore+ruleD.getStore();
						log.info("#toScoreResult() 银行卡收入！");
						continue;
					}
					}
				}
				
				//银行卡支出
				if (ruleD.getRuleCode().equalsIgnoreCase("FLK-15")) {
					if (StringUtils.isNotBlank(ruleD.getMinValue()) && StringUtils.isNotBlank(ruleD.getMxValue())) {
						if ((toPay+1<=Integer.parseInt(ruleD.getMinValue()) || toPay>Integer.parseInt(ruleD.getMxValue())) &&  ispay==0) {
							ispay=1;
							nutScore=nutScore+ruleD.getStore();
							log.info("#toScoreResult() 银行卡支出！");
							continue;
						}
					}
				}
				
			}
			
			score=score-ruleD.getStore();
			
		}
		
		//减分项计算
		List<RuleData> typeSumList=scoreDao.findTypeSum(ruleData);
		for (int i = 0; i < typeSumList.size(); i++) {
			RuleData typeSum=typeSumList.get(i);
			if (typeSumList.get(i).getType().contains("学信")) {
				chsiScore=typeSum.getSum()-chsiScore;
				request.setAttribute("chsiScore", chsiScore);
			}
			
			if (typeSumList.get(i).getType().contains("公积金")) {
				gjjScore=typeSum.getSum()-gjjScore;
				request.setAttribute("gjjScore", gjjScore);
			}
			
			if (typeSumList.get(i).getType().contains("社保")) {
				shebaoScore=typeSum.getSum()-shebaoScore;
				request.setAttribute("shebaoScore", shebaoScore);
			}
			
			if (typeSumList.get(i).getType().contains("运营商")) {
				yysScore=typeSum.getSum()-yysScore;
				request.setAttribute("yysScore", yysScore);
			}
			
			if (typeSumList.get(i).getType().contains("银行卡")) {
				nutScore=typeSum.getSum()-nutScore;
				request.setAttribute("nutScore", nutScore);
			}
		}
		
		request.setAttribute("netTime", netTime);
		request.setAttribute("calledCount", calledCount);
		request.setAttribute("callCount", callCount);
		request.setAttribute("total_call_time", total_call_time);
		log.info("#toScoreResult() 最后分数为："+score);
		request.setAttribute("score", score);
		log.info("#toScoreResult() 进入评分页面！");
		return "/buyer/report";
	}

	@IgnoreAuth
	@RequestMapping({ "verify" })
	public String verify(HttpServletRequest request, AntifraudUser user,HttpServletResponse response)
			throws Exception { 
		
		try {
			
		

		Gson gson = new Gson();
		
		List<DataInterfaceManagement> dataList=verifyDao.getDataList();
	
		System.out.println(gson.toJson(dataList));
		for (int i = 0; i < dataList.size(); i++) {
			DataInterfaceManagement dataInterfaceManagement=dataList.get(i);
			if (dataInterfaceManagement.getShortName().equalsIgnoreCase("shumei")) {
				smtype=Integer.parseInt(dataInterfaceManagement.getState());
			}
			
            if (dataInterfaceManagement.getShortName().equalsIgnoreCase("tongdun")) {
            	tdtype=Integer.parseInt(dataInterfaceManagement.getState());
			}
		}
		
		Timestamp now = new Timestamp(System.currentTimeMillis());
		String shopId = null;
		String userId = null;

		if (request.getSession().getAttribute("SHOP_ID")!=null) {
			 shopId = request.getSession().getAttribute("SHOP_ID").toString();
			 userId = request.getSession().getAttribute("USER_ID").toString();
		}else{
			 PrintWriter out = response.getWriter();  
		        out.println("<html>");      
		        out.println("<script>");      
		        out.println("window.open ('"+request.getContextPath()+"/index','_top')");      
		        out.println("</script>");      
		        out.println("</html>");    
			return null;
		}
		
		ZxExternalData zx = new ZxExternalData();
		zx.setIdNumber(user.getIdNumber());
		zx.setShopId(shopId);
		List<ZxExternalData> list = verifyDao.findOne(zx);

		// 判断是否过了30天有效时间
		for (int j = 0; j < list.size(); j++) {
			if (now.getTime() < list.get(j).getValidTime().getTime()) {
				if (list.size() >= 1) {
					if (list.get(j).getDataSource()!=null) {
					log.info("#verify() 查询用户在30天有效时间内！{}", user.getName());
					JDEntity sMJDDetail = new JDEntity();
					BlackEntity sMHMDDetail = new BlackEntity();
					TdRiskReturn tdRiskReturn = new TdRiskReturn();
					for (int i = 0; i < list.size(); i++) {
						String datasource = list.get(i).getDataSource();
						if (list.get(i).getIntertype().equals("1")) {
							sMJDDetail = gson.fromJson(datasource,
									JDEntity.class);
						}
						if (list.get(i).getIntertype().equals("2")) {
							sMHMDDetail = gson.fromJson(datasource,
									BlackEntity.class);
						}
						if (list.get(i).getType().equals("1") || list.get(i).getType()==1) {
							tdRiskReturn = gson.fromJson(datasource,
									TdRiskReturn.class);
						}
						
						//保存外部数据主键id
						user.setId(list.get(i).getId());

					}
				
					setRequest(sMJDDetail, request, sMHMDDetail, user, 0,
							tdRiskReturn);
					
				}else{
					Unknown(request, user);	//跳未知页面		
				}
					
				}
				return "/buyer/queryReport";
			}
			break;
		}

		log.info("#verify() 查询用户为新用户或者超过了30天有效时间，重新请求查询接口：{}", user.getName());

		String sm_accessKey = PropertiesUtils.getProperty("sm_accessKey");
		SMJDEntity smjd = new SMJDEntity();
		SMJDData data = new SMJDData();
		data.setPhone(user.getPhone());
		data.setName(user.getName());
		data.setPrcid(user.getIdNumber());
		data.setCardid(user.getCardNumber());
		request.setAttribute("verifyuser", user);

		smjd.setAccessKey(sm_accessKey);
		smjd.setData(data);

		log.info("#verify() 反欺诈信息核实请求参数：" + gson.toJson(smjd));

		try {

			JDEntity sMJDDetail = new JDEntity();
			BlackEntity sMHMDDetail = new BlackEntity();
			String resjdJson = null;
			String reshmdJson = null;

			if (smtype == 0) {
				// 数美借贷接口
				String sm_jd_url = PropertiesUtils.getProperty("sm_jd_url");
				resjdJson = HttpUtils.doPost(sm_jd_url, gson.toJson(smjd),
						null, 3, 10, "utf-8");
				log.info("#doPost() 数美借贷接口返回信息：" + resjdJson);
				sMJDDetail = (JDEntity) gson
						.fromJson(resjdJson, JDEntity.class);

				// 数美黑名单接口
				String sm_hmd_url = PropertiesUtils.getProperty("sm_hmd_url");
				reshmdJson = HttpUtils.doPost(sm_hmd_url, gson.toJson(smjd),
						null, 3, 10, "utf-8");
				log.info("#doPost() 数美黑名单接口返回信息：" + reshmdJson);
				sMHMDDetail = (BlackEntity) gson.fromJson(reshmdJson,
						BlackEntity.class);
			}

			// 接口数据入库处理
			if (smtype==0 || tdtype==0) {
				String id = verifyService.saveAll(resjdJson, reshmdJson, user,
						shopId, userId, smtype);
				user.setId(id);
			}
			
			//反欺诈扣款
			if (user.getDivision().equals("1")) {
				verifyService.debit(request, "0");
			}
			
			//评分卡扣款
			if (user.getDivision().equals("2")) {
				verifyService.debit(request, "1");
				
			}

			// 返回前台信息公共方法
			setRequest(sMJDDetail, request, sMHMDDetail, user, 1,
					new TdRiskReturn());

		} catch (Exception e) {
			return "/buyer/queryReport";
		}

		return "/buyer/queryReport";
		
		} catch (Exception e) {
			Unknown(request, user);  //跳未知页面
		}
		return null;
	}

	@ResponseBody
	@IgnoreAuth
	@RequestMapping({ "cost" })
	public String judgecost(HttpServletRequest request,String type) {

		if (type.equalsIgnoreCase("GJJ")) {
			type=3+"";
		}
		if (type.equalsIgnoreCase("SHE_BAO")) {
			type=4+"";
		}
		// 判断用户的剩余金额
		String shopId = null;
		if (request.getSession().getAttribute("SHOP_ID")!=null) {
			 shopId = request.getSession().getAttribute("SHOP_ID").toString();
		}
		
		ZxExternalData zxc = new ZxExternalData();
		zxc.setShopId(shopId);
		ZxExternalData zxcost = verifyDao.findcost(zxc);
		
		ShopPrice shopPrice=new ShopPrice();
		shopPrice.setShopId(shopId);
		shopPrice.setType(type);
		shopPrice=payRecordDao.findPrice(shopPrice);
	
		if (shopPrice!=null && zxcost!=null) {
			if (zxcost.getBalance().intValue()<shopPrice.getPrice().intValue()) {
				// 剩余金额不足
				return Enums.RespCode.INSUFFICIENT_SURPLUS.getRespCode();
			}
		}
		return Enums.RespCode.REMAINING_SUFFICIENT_AMOUNT.getRespCode();

	}

	public void setRequest(JDEntity jDEntity, HttpServletRequest request,
			BlackEntity black, AntifraudUser user, int type,
			TdRiskReturn tdRiskReturn) {
		try {
		SMHMDDetail smhmddetail = new SMHMDDetail();
		request.setAttribute("verifyuser", user);
		Gson gson = new Gson();
		
		if (user.getDivision().equals("2")) {
			request.setAttribute("orderType", "1");
			user.setType("1");
		}else if(user.getDivision().equals("3")){
			user.setType("2");
		}else{
			user.setType("0");
		}

		if (!gson.toJson(black).equals("{}")) {
			// 黑名单
			if ((StringUtils.isNotBlank(black.getDetail().getIn_black()))
					&& (black.getDetail().getIn_black().equals("1"))) {
				log.info("#verify() 命中黑名单：{}" + user.getIdNumber());
				getShHmd(black);
				request.setAttribute("ver", black.getDetail());
				return;
			}

			// 多头借贷
			if (Integer.parseInt(jDEntity.getDetail().getItfin_registers()) > 1) {
				log.info("#verify() 命中多头借贷：{}" + user.getIdNumber());
				SMHMDDetail hmd = black.getDetail();
				getShDtjd(black, jDEntity, hmd);
				request.setAttribute("ver", hmd);
				if (user.getDivision().equals("2")) {
					request.setAttribute("nextType", "1");
				}

				return;
			}

		}
		
		// 调同盾的接口
		String resquesyJson = gson.toJson(tdRiskReturn);
		//数据源开关
		if (tdtype==0) {
			if (gson.toJson(tdRiskReturn).equals("{}") || tdRiskReturn == null) {
				resquesyJson = tdInterface(user);
				if (type == 1) {
					verifyService.save(user.getId(), resquesyJson);
				}
				tdRiskReturn = gson.fromJson(resquesyJson, TdRiskReturn.class);
			}
		}

		// 同盾黑名单
		if (resquesyJson.contains("black_list")) {
			getTdHmd(smhmddetail, tdRiskReturn);
			smhmddetail.setGrade(Enums.RespCode.BLACKLIST.getRespCode());
			request.setAttribute("ver", smhmddetail);
			return;
		}

		// 同盾多头借贷
		String count = null;
		if (!gson.toJson(tdRiskReturn).equals("{}")) {

			List<RISK_ITEMS> ristList = tdRiskReturn.getRisk_items();
			if (ristList.size()>0) {
				getTdDtjd(smhmddetail, ristList);

				for (int i = 0; i < ristList.size(); i++) {
					if (tdRiskReturn.getRisk_items().get(i).getItem_detail() != null) {
						count = tdRiskReturn.getRisk_items().get(i)
								.getItem_detail().getPlatform_count()
								+ "";
						if (getBNum(count) && Integer.parseInt(count) > 1) {
							smhmddetail.setGrade(Enums.RespCode.BULL_LENDING
									.getRespCode());
							request.setAttribute("ver", smhmddetail);
							if (user.getDivision().equals("2")) {
								request.setAttribute("nextType", "1");
							}
							return;
						}
					}
				}
			}
			


		}

		// 未知用户
		log.info("#verify() 命中未知：{}" + user.getIdNumber());

		smhmddetail.setGrade(Enums.RespCode.UNKNOWN.getRespCode());
		smhmddetail.setItfin_loan_overdues_7d(Constant.DONT_RECORDS);
		request.setAttribute("ver", smhmddetail);
		if (user.getDivision().equals("2")) {
			request.setAttribute("nextType", "1");
		}
		} catch (Exception e) {
			Unknown(request, user);
		}
		return;
	}
	
	//数美黑名单
	public void getShHmd(BlackEntity black){
		black.getDetail().setRemarks1(Constant.OVERDUE_NUMBER_7DAYS);
		black.getDetail().setRemarks2(Constant.OVERDUE_TIME_7DAYS);
		black.getDetail().setRemarks3(Constant.OVERDUE_NUMBER_30DAYS);
		black.getDetail().setRemarks4(Constant.OVERDUE_TIME_30DAYS);
		black.getDetail().setRemarks5(Constant.OVERDUE_TIME);
		black.getDetail().setRemarks6(Constant.OVERDUE_NUMBER);
		black.getDetail().setGrade(
				Enums.RespCode.BLACKLIST.getRespCode());

		// 逾期时长格式转换
		if (StringUtils.isNotBlank(black.getDetail()
				.getItfin_loan_overdue_duration())
				&& black.getDetail().getItfin_loan_overdue_duration()
						.contains("M")) {
			String overdue = black.getDetail()
					.getItfin_loan_overdue_duration();
			String str = overdue.substring(1, overdue.length());
			black.getDetail().setItfin_loan_overdue_duration(str + "期");
		}

		if (StringUtils.isNotBlank(black.getDetail()
				.getItfin_loan_overdue_duration_7d())
				&& black.getDetail()
						.getItfin_loan_overdue_duration_7d()
						.contains("M")) {
			String overdue7 = black.getDetail()
					.getItfin_loan_overdue_duration_7d();
			String str = overdue7.substring(1, overdue7.length());
			black.getDetail().setItfin_loan_overdue_duration_7d(
					str + "期");
		}

		if (StringUtils.isNotBlank(black.getDetail()
				.getItfin_loan_overdue_duration_30d())
				&& black.getDetail()
						.getItfin_loan_overdue_duration_30d()
						.contains("M")) {
			String overdue30 = black.getDetail()
					.getItfin_loan_overdue_duration_30d();
			String str = overdue30.substring(1, overdue30.length());
			black.getDetail().setItfin_loan_overdue_duration_30d(
					str + "期");
		}
		
	}
	
	//数美多头借贷
	public void getShDtjd(BlackEntity black,JDEntity jDEntity,	SMHMDDetail hmd){
		
		hmd.setRemarks1(Constant.APPLICATION_7DAYS);
		hmd.setRemarks2(Constant.APPLICATION_30DAYS);
		hmd.setRemarks3(Constant.OVERDUE_7DAYS);
		hmd.setRemarks4(Constant.REFUSE_30DAYS);
		hmd.setItfin_loan_overdues_30d(black.getDetail()
				.getItfin_loan_overdues_7d());
		hmd.setItfin_loan_overdues_7d(jDEntity.getDetail()
				.getItfin_loan_applications_7d());
		hmd.setItfin_loan_overdue_duration_7d(jDEntity.getDetail()
				.getItfin_loan_applications_30d());
		hmd.setItfin_loan_overdue_duration_30d(jDEntity.getDetail()
				.getItfin_loan_refuses_30d());
		hmd.setGrade(Enums.RespCode.BULL_LENDING.getRespCode());

	}
	
	//同盾黑名单
	public void getTdHmd(SMHMDDetail smhmddetail,TdRiskReturn tdRiskReturn){
		Gson gson=new Gson();
		smhmddetail.setRemarks1(Constant.OVERDUE_NUMBER_7DAYS);
		smhmddetail.setRemarks2(Constant.OVERDUE_TIME_7DAYS);
		smhmddetail.setRemarks3(Constant.OVERDUE_NUMBER_30DAYS);
		smhmddetail.setRemarks4(Constant.OVERDUE_TIME_30DAYS);
		smhmddetail.setRemarks5(Constant.OVERDUE_TIME);
		smhmddetail.setRemarks6(Constant.OVERDUE_NUMBER);

		smhmddetail.setItfin_loan_overdues_7d("无"); // 7天逾期个数
		smhmddetail.setItfin_loan_overdue_duration_7d("无"); // 7天逾期时长

		smhmddetail.setItfin_loan_overdue_duration("无"); // 逾期时长

		for (int i = 0; i < tdRiskReturn.getRisk_items().size(); i++) {
			ITEM_DETAIL item_detail = tdRiskReturn.getRisk_items().get(i)
					.getItem_detail();
			if (item_detail != null
					&& item_detail.getDiscredit_times() != null) {
				smhmddetail.setItfin_loan_overdues(item_detail
						.getDiscredit_times() + ""); // 逾期个数
			}
			if (gson.toJson(item_detail).contains("overdue_details")) {
				List<OVERDUE_DETAILS> overDueList = item_detail
						.getOverdue_details();
				for (int j = 0; j < overDueList.size(); j++) {
					if (gson.toJson(overDueList.get(j)).contains("0, 30")) {
						smhmddetail.setItfin_loan_overdues_30d(overDueList
								.get(j).getOverdue_count() + ""); // 30天逾期个数

						smhmddetail
								.setItfin_loan_overdue_duration_30d("1期"); // 30天逾期时长
					}

				}
			}
		}
	}
	
	//同盾多头借贷
	public void getTdDtjd(SMHMDDetail smhmddetail,List<RISK_ITEMS> ristList){
		for (int i = 0; i < ristList.size(); i++) {

			smhmddetail.setRemarks1(Constant.APPLICATION_7DAYS);
			smhmddetail.setRemarks2(Constant.APPLICATION_30DAYS);
			smhmddetail.setRemarks3(Constant.OVERDUE_7DAYS);
			smhmddetail.setRemarks4(Constant.REFUSE_30DAYS);

			smhmddetail.setItfin_loan_overdues_30d("无");

			smhmddetail.setItfin_loan_overdue_duration_30d("无");

			RISK_ITEMS riskitems = ristList.get(i);
			if (riskitems.getItem_name().contains("7")
					&& riskitems.getItem_name().contains("多个平台")) {
				smhmddetail.setItfin_loan_overdues_7d(riskitems
						.getItem_detail().getPlatform_count() + ""); // 7天申请平台数
			}

			if (riskitems.getItem_name().contains("1个月内申请人在多个平台申请借款")
					&& riskitems.getItem_name().contains("多个平台")) {
				smhmddetail.setItfin_loan_overdue_duration_7d(riskitems
						.getItem_detail().getPlatform_count() + ""); // 30天申请平台数
			}

		}
	}

	// 同盾接口
	public static String tdInterface(AntifraudUser user) {
		Gson gson = new Gson();
		String td_submit_url = PropertiesUtils.getProperty("td_submit_url");
		String body = "name=" + user.getName() + "&id_number="
				+ user.getCardNumber() + "&mobile=" + user.getPhone() + "";
		String ressubmitJson = HttpUtils.doPostx(td_submit_url, body, null, 3,
				10, "utf-8");
		TdRiskReturn tdRiskReturn = gson.fromJson(ressubmitJson,
				TdRiskReturn.class);

		String td_query_url = PropertiesUtils.getProperty("td_query_url");
		String td_query_url_request = td_query_url + "&report_id="
				+ tdRiskReturn.getReport_id();
		String resquesyJson = HttpUtils.doGet(td_query_url_request, null, 3,
				10, "utf-8");
		log.info("#toantiFraud() 同盾返回信息：{}" + resquesyJson);
		
		return resquesyJson;
	}

	public static boolean getBNum(String str) {
		boolean isNum = str.matches("[0-9]+");
		return isNum;
	}

	
	//数据字典取值
	@ResponseBody
	@IgnoreAuth
	@RequestMapping({ "dict" })
	public List<DictEntity> dict(HttpServletRequest request,String type) {
		DictEntity dictEntity=new DictEntity();
		dictEntity.setDict_type(type); 
		List<DictEntity> dictList=verifyDao.findDict(dictEntity);
		return dictList;

	}
	
	
		@ResponseBody
		@IgnoreAuth
		@RequestMapping({ "getShopPrice" })
		public List<ShopPrice> getShopPrice(HttpServletRequest request,HttpServletResponse response) throws IOException {
			Gson gson=new Gson();
			ShopPrice shopPrice=new ShopPrice();
			String shopId=getShopId(request, response);
			shopPrice.setShopId(shopId);
			List<ShopPrice> list=payRecordDao.findPriceList(shopPrice);
			
			return list;
		}
	
		
    public static String getStringDate(Date date){
    	SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
		String str=sdf.format(date);  
		return str;
     }
    
    public static String getString16Date(Date date){
    	SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
		String str=sdf.format(date);  
		return str;
     }
    
    public static String getString16Date2(Date date){
    	SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmss");  
		String str=sdf.format(date);  
		return str;
     }
    
    public static String lastMonth(){
    	Calendar c = Calendar.getInstance();
		  c.add(Calendar.MONTH, -1);
		  SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM");
		  String time = format.format(c.getTime());
		  return time;
    }
    
    public static List<String> getThree(List<String> list){
    	List<String> reslist=new ArrayList<String>();
    	 Map<String,Integer> map = new HashMap<String,Integer>();
	        //整理每个字符串出现次数
	        TreeSet<Integer> numset = new TreeSet<Integer>();
	        for(int i = 0;i < list.size();i++){
	            int len = list.size();
	            String s = (String)list.get(i);
	            Set<String> set = new HashSet<String>();
	            set.add(s);
	            list.removeAll(set);
	            map.put(s, len - list.size());
	            numset.add(len - list.size());
	            i = 0;
	        }
	         
	        //输出出现次数最多的10个字符串。如果字符串少于10个，则全部输出后终止
	        List<Integer> nums = new ArrayList<Integer>(numset);
	        int j = 1;
	        
	        	for(int i = nums.size() - 1; i > 0;i--){
		            for(String key : map.keySet()){
		                if(4 == j){
		                    break;
		                }
		                if(map.get(key) == nums.get(i)){
		                	reslist.add(key);
		                    j++;
		                   
		                }
		            }           
		        }
	        
	        
	        return reslist;
    }
    
    public static String getShopId(HttpServletRequest request,HttpServletResponse response) throws IOException{
    	String shopId=null;
		if (request.getSession().getAttribute("SHOP_ID")!=null) {
			 shopId = request.getSession().getAttribute("SHOP_ID").toString();  //商户Id
		}else{
			 PrintWriter out = response.getWriter();  
		        out.println("<html>");      
		        out.println("<script>"); 
		        out.println("window.open ('"+request.getContextPath()+"/index','_top')");      
		        out.println("</script>");
		        out.println("</html>");
			return null;
		}
		return shopId;
    } 
    
    
    public static void Unknown(HttpServletRequest request,AntifraudUser user){
    	SMHMDDetail smhmddetail=new SMHMDDetail();
		smhmddetail.setGrade(Enums.RespCode.UNKNOWN.getRespCode());
		smhmddetail.setItfin_loan_overdues_7d(Constant.DONT_RECORDS);
		request.setAttribute("ver", smhmddetail);
		if (user.getDivision().equals("2")) {
			request.setAttribute("nextType", "1");
		}
		if (user.getDivision().equals("2")) {
			request.setAttribute("orderType", "1");
			user.setType("1");
		}else if(user.getDivision().equals("3")){
			user.setType("2");
		}else{
			user.setType("0");
		}
		request.setAttribute("verifyuser", user);		
    }

	public static void main(String[] args) {
	
	}
}
